package bdz.projects.lavender.opsm.ui {
	import bdz.common.display.DisplayLoader;
	import bdz.common.events.GenericEvent;
	import bdz.projects.lavender.opsm.model.FlipCollection;
	import bdz.projects.lavender.opsm.vo.ProductVO;
	import com.soulwire.display.PaperSprite;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import com.greensock.*;
	import com.greensock.easing.*;
	
	/**
	 * ...
	 * @author ...
	 */
	public class ProductDetailImageCopy extends Sprite	{
		private var _image:DisplayLoader;
		private var _pvo:ProductVO;
		private var _imageList:ProductImageList;
		private var _bg:Sprite;
		private var _defW:Number = 720;
		private var _defH:Number = 390;
		private var _productCopy:ProductCopy;
		private var _images:Array;
		private var _thumbW:Number;
		private var _thumbH:Number;
		private var _collection:FlipCollection;
		private var _colorList:ProductColorList;
		private var _mainImageFlip:FlipBox;
		private var _backImage:DisplayLoader;
		function ProductDetailImageCopy() {
			addEventListener(Event.ADDED_TO_STAGE, initializeComponent);
		}
		private function initializeComponent(evt:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, initializeComponent);
			_bg = new Sprite();
			_bg.graphics.beginFill(0xffffff, 1);
			_bg.graphics.drawRect(0, 0, _defW, _defH);
			_bg.graphics.endFill();
			addChild(_bg);
			
			
			_image = new DisplayLoader();
			_image.y = 23;
			_image.x = 30;
			_image.addEventListener(Event.COMPLETE, onMainImageLoaded);
			_image.source = _pvo.defaultImage;
			addChild(_image);
			
			
			//addChild(_image);
			createRightSideCopy();
			createImageList();
			createColorList();
		}	
		protected function onImageListComplete(evt:Event):void {
			
			dispatchEvent(new GenericEvent(GenericEvent.READY));
		}
		protected function onMainImageLoaded(evt:Event):void {
			dispatchEvent(evt);
		}
		protected function createColorList():void {
			_colorList = new ProductColorList();
			_colorList.dataProvider = createColorListProvider();
			_colorList.y = 55;
			_colorList.x = _productCopy.x + 185;
			_colorList.addEventListener(GenericEvent.CLICKED, onColorListClicked);
			addChild(_colorList);
		}
		protected function onColorListClicked(evt:GenericEvent):void {
			dispatchEvent(evt);
		}
		protected function createColorListProvider():Array {
			//remove slice later.
			return _collection.slice(0, 4);
			return _collection.getProductsWithID(product.productID);
		}
		protected function createImageList():void {
			_imageList = new ProductImageList(_images);
			_imageList.imageHeight = _thumbH;
			_imageList.imageWidth = _thumbW;
			_imageList.addEventListener(GenericEvent.CLICKED, onImageListClicked);
			_imageList.addEventListener(Event.COMPLETE, onImageListComplete);
			
			_imageList.y = _image.y + _image.height + 300;
			//_imageList.y = 600;
			addChild(_imageList);
		}
		protected function onImageListClicked(evt:GenericEvent):void {
			var csource:String = _image.source;
			_image.source = evt.data.targ.source;
			evt.data.targ.source = csource;
			evt.data.targ.alpha = 0;
			_image.alpha = 0;
			TweenLite.to(evt.data.targ, 1, { alpha:1, ease:Strong.easeInOut } );
			TweenLite.to(_image, 1, { alpha:1, ease:Strong.easeInOut } );
			
		}
		protected function createRightSideCopy():void {
			_productCopy = new ProductDetailsRightCopy() as ProductCopy;
			_productCopy.product = product;
			_productCopy.x = 500;
			_productCopy.y = 30;
			addChild(_productCopy);
		}
		public function loadThumbnails():void {
			_imageList.loadThumbs();
		}
		public function set collection(fp:FlipCollection):void {
			_collection = fp;
		}
		public function get collection():FlipCollection {
			return _collection;
		}
		public function set product(vo:ProductVO):void {
			_pvo = vo;
		}
		public function get product():ProductVO {
			return _pvo;
		}
		public function set images(arr:Array):void {
			_images = arr;
		}
		public function get images():Array {
			return _images;
		}
		public function set thumbWidth(n:Number):void {
			_thumbW = n;
		}
		public function get thumbWidth():Number {
			return _thumbW;
		}
		public function set thumbHeight(n:Number):void {
			_thumbH = n;
		}
		public function get thumbHeight():Number {
			return _thumbH;
		}
		
		public function destroy() {
			
		}
	}
	
}